package com.ansion.commonchat.startup.workmanager.bwork;

import android.annotation.SuppressLint;
import android.content.Context;

import androidx.annotation.NonNull;

import com.ansion.commonchat.startup.workmanager.bwork.impl.BWorkManagerImpl;
import com.google.common.util.concurrent.ListenableFuture;

import java.util.Collections;
import java.util.List;
import java.util.UUID;


/**
 * Created by wanghongjie on 2023/5/5
 * Describe : 管理和调度后台任务（Work）的执行。入口类。
 */
@SuppressLint("AddedAbstractMethod")
public abstract class BWorkManager {

    public static @NonNull
    BWorkManager getInstance(@NonNull Context context) {
        return BWorkManagerImpl.getInstance(context);
    }

    @NonNull
    public final BOperation enqueue(@NonNull BWorkRequest workRequest) {
        return enqueue(Collections.singletonList(workRequest));
    }

    @NonNull
    public abstract BOperation enqueue(@NonNull List<? extends BWorkRequest> requests);

    public final @NonNull
    BWorkContinuation beginWith(@NonNull BOneTimeWorkRequest work) {
        return beginWith(Collections.singletonList(work));
    }

    public abstract @NonNull
    BWorkContinuation beginWith(@NonNull List<BOneTimeWorkRequest> work);

    public abstract @NonNull
    ListenableFuture<BWorkInfo> getWorkInfoById(@NonNull UUID id);

    public abstract @NonNull
    ListenableFuture<List<BWorkInfo>> getWorkInfosByTag(@NonNull String tag);

    public abstract void removeWorkListenerById(long workListenerId);

    public abstract void logout();

    protected BWorkManager() {
    }
}
